package com.atguigu.srb.oss.controller;

import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@Api(tags = "文件管理模块")
@RequestMapping("/api/oss")
public class OssController {
    @Resource
    OssService ossService;

    @ApiOperation("文件上传")
    @PostMapping("upload")
    //参数2： 上传的文件保存到oss桶中的哪个目录下
    public ResponseVo upload(
            MultipartFile file,
            @RequestParam("module") String module
    ){
        String path = ossService.upload(file, module);
        return ResponseVo.ok().data("path", path);
    }

    @ApiOperation("文件删除")
    @DeleteMapping("delete")
    public ResponseVo delete(
            @RequestParam("path") String path
    ){
        ossService.deleteFile(path);
        return ResponseVo.ok().message("文件删除成功");
    }
}
